
define([
	'vue',
	'config',
	'common',
	'../model/upLoadList',
	'moment',
	'../model/downLoadList'
	],function(Vue,config,utils,upLoadList,moment,downLoadList){
	'use strict';
    	
	var expensesRecord_shopView=new Vue({
		el:'#app',
		data:{
			items:'',
			page: 1,
			totalPage:0,
			isLoadMore:0,
			pageSize:'',
			listheight:'',

			start:'',
			end:'',
			finishUpload:true,
		},
		filters:{
			moment:function(date){
				var Date = moment(date*1000).format('YYYY-MM-DD');
				var arr = Date.split('-');
				return arr[1]+'-'+arr[2];
			},
			abbreviation:function(value){
	            var value = value >= 10000 ? (value*1/10000).toFixed(2) + '万' : (value*1).toFixed(0);
	            return value;
        	}
		},
		watch:{
			items: function(to,from){
				if(to.length == 0 && this.items !== ""){
					$('.error404').show();
				}else{
					$('.error404').hide();
				}
			}
		},
		directives: {
		  scroll: {
		    inserted: function (el, binding){
		      var binding =binding;
		      window.addEventListener('scroll',function() {
		       		var fnc = binding.value;   
   					fnc();
		      })
		    }
		  }
		},
		created:function(){
			utils.userToken();
			
			var _this=this;
			//_this.pageSize = parseInt(Math.ceil(($('body').height()-$('.headTitle').height())/43), 10);
			_this.pageSize = 30;
			upLoadList.ajax(utils.getWebUrl('declaration/list'),{
				pageSize: _this.pageSize,
				page: _this.page
			},function(res){
				var items = new Array();
				$.each(res.data.list,function(k,v){
					if(v.status!=6){
						items.push(v)
					}
				})
				_this.items = items;
				_this.totalPage = res.data.totalPage;
			})
		},
		methods:{
			back: function(){
				var userTypeId =utils.getData('userTypeId');
				if(userTypeId == 5){
					window.location.href='shopInfo.html';
				}else{
					window.location.href='userInfo.html';
				}
			},
			loadMore:function(event){
				var _this = this;
				
				if ((upLoadList.getScrollTop() + upLoadList.getClientHeight() >= upLoadList.getScrollHeight())&&_this.page<_this.totalPage&&_this.finishUpload) {
		           	_this.page = _this.page+1;
		           	var data = {
		           		pageSize: _this.pageSize,
						page: _this.page
		           	}
					upLoadList.ajax(utils.getWebUrl('declaration/list'),data,function(res){
		            	var items = new Array();
						$.each(res.data.list,function(k,v){
							if(v.status!=6){
								items.push(v)
							}
						})
						_this.items = _this.items.concat(items);
						_this.totalPage = res.data.totalPage;
					})
		        }
			},

			Start:function(event){

				var touch = event.targetTouches[0];
				this.start = touch.pageY;

			},

			Move:function(event){
				var touch = event.targetTouches[0];
				this.end = (this.start - touch.pageY);
				var slideDown1 = $('#pullDown1');
				//下滑才执行操作 
                if(this.end < 0){
                	
                	slideDown1.text('下拉刷新  ↓');
	        		slideDown1.show();
	        		slideDown1[0].style.height =  (parseInt("0px")-this.end) + "px";
	        		if(this.end < -48){
	        			/*slideDown1.hide(); 
	        			downLoadList.slideDownStep1(this.end);*/
	        			slideDown1.text('松手开始更新  ↑')
	        		}
                }else{
                	slideDown1.hide();
                }
			},

			End:function(event){
				var _this = this;
				if(this.end >0){  
					slideDown1.hide();
	            }else{ 

	                if(this.end < -48 && document.body.scrollTop == 0){
	                	var slideDown1 = $('#pullDown1');
	                	var slideDown2 = $('#pullDown2');

						slideDown1.hide();
				        slideDown2.show();

	                	downLoadList.slideDownStep2(); 
		                //刷新成功则 
		                //模拟刷新成功进入第三步
		                _this.page = 1;
		                $('#pullDown3').hide();
		                var data = {
							page: _this.page,
							pageSize: _this.pageSize
						}
		                utils.ajax(utils.getWebUrl('declaration/list'),data,
		                	'POST',
		                	function(res){
								var items = new Array();
								$.each(res.data.list,function(k,v){
									if(v.status!=6){
										items.push(v)
									}
								})
								_this.items = items;
								_this.totalPage = res.data.totalPage;
						},null,function(){
							downLoadList.slideDownStep3();
						})
		                
	                }else{
	                	var slideDown1 = $('#pullDown1');
		        		slideDown1.hide();
	                }
	            }
			},

			toStatus:function(event){
				var id = $(event.currentTarget).data('id');
				var status = $(event.currentTarget).data('status');
				//判断跳转
				switch (status) {
					case 0:  //已保存(待上传消费凭证)
						
						break;
					case 1:   //已提交
						window.location.href = "consumerAudit.html?id="+id;
						break;
					case 2:   //已撤回
						window.location.href = "expensesRecord_revoked.html?id="+id;
						break;
					case 3:   //审核未通过
						window.location.href = "consumerAudit.html?id="+id;
						break;
					case 4:   //待上传凭证(汇款凭证)
						
						break;
					case 5:   //已上传凭证(汇款凭证)
						window.location.href = "consumerAudit.html?id="+id;
						break;
					case 6:   //审核通过
						window.location.href = "consumerAudit.html?id="+id;
						break;
					case 7:   //审核通过
						window.location.href = "consumerAudit.html?id="+id;
						break;
				}
			},
			//上传汇款凭证
			toTransferVoucher:function(event){
				var id = $($(event.currentTarget).parents('li')).data('id');
				window.location.href="remittanceVoucher.html?id="+id;
			},
			supplement:function(event){
				var id = $($(event.currentTarget).parents('li')).data('id');
				window.location.href="consumptionCertificate.html?id="+id+'&backType=2';;
			},
			toDelect:function(event){
				var id = $($(event.currentTarget).parents('li')).data('id');
				window.location.href="expensesRecord_revocation.html?id="+id;
			}	
		}
	})

	return expensesRecord_shopView;
});